<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>移动端搜索页</title>
    <link rel="stylesheet" href="css/return.css/reset.css">
    <script src="js/flexible.js"></script>
    <style>
        body,
        html {
            width: 100%;
            /* height: 15rem; */
            /* background-color: #252B3A; */
        }

        header {
            padding: 10px;
            background-color: #f5f5f5;
            border-bottom: 1px solid #ddd;
            text-align: center;
            position: relative;
            z-index: 1;
        }

        h1 {
            font-size: 52px;
            margin: 0;
            color: #333;
        }

        .search-box {
            padding: 10px;
            background-color: #fff;
            border-bottom: 1px solid #ddd;
            position: relative;
            z-index: 1;
        }

        .search-input {
            width: 100%;
            height: 120px;
            padding: 10px;
            border: 1px solid #ddd;
            border-radius: 60px;
            box-sizing: border-box;
            font-size: 28px;
            color: #333;
            outline: none;
        }

        .search-button {
            /* width: 100px;
            height: 50px; */
            position: absolute;
            right: 35px;
            top: 50%;
            transform: translateY(-50%);
            width: 200px;
            height: 105px;
            background-color: rgb(222, 51, 51);
            border-radius: 29%;
            display: flex;
            align-items: center;
            justify-content: center;
            cursor: pointer;
            color: #fff;
        }

        .search-button:hover {
            background-color: #ddd;
        }

        .hot-search {
            padding: 10px;
            background-color: #fff;
            border-bottom: 1px solid #ddd;
        }

        .hot-search-title {
            font-size: 42px;
            margin: 0;
            color: #333;
        }

        .hot-search-list {
            margin-top: 10px;
            display: flex;
            flex-wrap: wrap;
        }

        .hot-search-item {
            padding: 5px 10px;
            background-color: #eee;
            margin-right: 10px;
            margin-bottom: 10px;
            border-radius: 20px;
            font-size: 42px;
            color: #666;
            cursor: pointer;
        }

        .hot-search-item:hover {
            background-color: #ddd;
        }

        .history-search {
            padding: 10px;
            background-color: #fff;
            position: relative;
            z-index: 0;
        }

        .history-search-title {
            font-size: 42px;
            margin: 0;
            color: #333;
        }

        .history-search-list {
            margin-top: 10px;
            display: flex;
            flex-wrap: wrap;
        }

        .history-search-item {
            padding: 5px 10px;
            background-color: #eee;
            margin-right: 10px;
            margin-bottom: 10px;
            border-radius: 20px;
            font-size: 45px;
            color: #666;
            cursor: pointer;
        }

        .history-search-item:hover {
            background-color: #ddd;
        }

        .clear-history {
            position: absolute;
            right: 10px;
            top: 50%;
            transform: translateY(-50%);
            font-size: 48px;
            color: #999;
            cursor: pointer;
        }

        .inouw {
            font-size: 48px;
            line-height: 100px;
            text-align: center;
            float: left;
            width: 200px;
            height: 100px;
            border-radius: 20px;
            background-color: skyblue;
            margin-left: 38%;
            margin-top: 100px;


        }

        .inouw:hover {
            background-color: greenyellow;
            color: #333;
        }
    </style>
</head>

<body>
    <header>
        <h1>搜索页</h1>
    </header>
    <div class="search-box">
        <input type="text" class="search-input" placeholder="请输入关键字">
        <div class="search-button">搜索</div>
    </div>
    <div class="hot-search">
        <h2 class="hot-search-title">热门推荐</h2>
        <div class="hot-search-list">
            <div class="hot-search-item">1-6年级</div>
            <div class="hot-search-item">三年模拟</div>
            <div class="hot-search-item">高考大纲</div>
        </div>
    </div>
    <div class="history-search">
        <h2 class="history-search-title">历史搜索</h2>
        <div class="history-search-list">
            <!-- 历史搜索列表 -->
        </div>
        <div class="clear-history">清空历史记录</div>
    </div>
    <a href="index.html" class="inouw">首页</a>
</body>

</html>
<script>
    let searchInput = document.querySelector('.search-input');
    let searchButton = document.querySelector('.search-button');
    let historyList = document.querySelector('.history-search-list');
    let clearHistory = document.querySelector('.clear-history');

    // 保存搜索记录
    function saveSearchHistory(keyword) {
        var history = localStorage.getItem('search_history');
        if (history) {
            history = JSON.parse(history);
        } else {
            history = [];
        }
        if (history.indexOf(keyword) === -1) {
            history.push(keyword);
        }
        localStorage.setItem('search_history', JSON.stringify(history));
    }

    // 渲染历史记录
    function renderHistory() {
        var history = localStorage.getItem('search_history');
        if (history) {
            history = JSON.parse(history);
            var html = '';
            history.forEach(function (keyword) {
                html += '<div class="history-search-item">' + keyword + '</div>';
            });
            historyList.innerHTML = html;
        }
    }

    // 清空历史记录
    function clearSearchHistory() {
        localStorage.removeItem('search_history');
        historyList.innerHTML = '';
    }

    // 绑定搜索按钮事件
    searchButton.addEventListener('click', function () {
        var keyword = searchInput.value.trim();
        if (keyword) {
            saveSearchHistory(keyword);
            renderHistory();
            // TODO: 处理搜索逻辑
        }
    });

    // 绑定历史记录点击事件
    historyList.addEventListener('click', function (event) {
        var target = event.target;
        if (target.classList.contains('history-search-item')) {
            var keyword = target.textContent;
            searchInput.value = keyword;
            saveSearchHistory(keyword);
            renderHistory();
            // TODO: 处理搜索逻辑
        }
    });

    // 绑定清空历史记录按钮事件
    clearHistory.addEventListener('click', function () {
        clearSearchHistory();
    });

    // 获取所有热门搜索项元素
    let hotSearchItems = document.querySelectorAll('.hot-search-item');

    // 遍历每个热门搜索项，为其添加点击事件监听器
    hotSearchItems.forEach(function (item) {
        item.addEventListener('click', function () {
            // 将点击的热门搜索项文本内容填充到搜索输入框
            searchInput.value = item.textContent;
        });
    });

    // 页面加载时渲染历史记录
    renderHistory();
</script>